﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DryWCS.App.UICore
{
    /// <summary>
    /// WaitingView.xaml 的交互逻辑
    /// </summary>
    public partial class WaitingView : Window, INotifyPropertyChanged
    {

        public event Action<Window> CallBack;
        private Window _window;
        private System.Timers.Timer Timer = new System.Timers.Timer();

        Random r = new Random();
        public WaitingView(string waitInfo, Window window)
        {
            InitializeComponent();
            WaitInfo = waitInfo;
            this.MouseLeftButtonDown += (sender, e) => { this.DragMove(); };
            this.DataContext = this;
            _window = window;
            Timer.Elapsed += Timer_Elapsed;
            Timer.Interval = r.Next(1500, 2000);
            Timer.Enabled = true;
        }

        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Application.Current?.Dispatcher.Invoke(() =>
            {
                CallBack?.Invoke(_window);
                this.Close();
            });
            Timer.Enabled = false;
        }

        public string WaitInfo { get; set; }




        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
